$(function(){
	var baseUrl = "/baichengwandianqingxiaowang/";
//省级地址下拉框发生改变
$("#province1").change(function(){
	var provinceId = $(this).val();
	var provinceName = $(this).find("option[value="+provinceId+"]").text();
	if(provinceName=='省份（必填）'){
		$("#city1").empty();
		$("#city1").prepend("<option value='city1'>市（选填）</option>");
		$("#county1").empty();
		$("#county1").prepend("<option value='county1'>县（选填）</option>");
	}else{
		$.ajax({
			type:"get",
			url:baseUrl+"customer/getAddressByParentId",
			data:{"parentId":provinceId},
			async:false,
			success:function(data){
				$("#city1").empty();
				$("#city1").prepend("<option value='city1'>市（选填）</option>");
				$("#county1").empty();
				$("#county1").prepend("<option value='county1'>县（选填）</option>");
				for(var i=0;i<data.length;i++){
					$("#city1").append('<option value='+data[i].addressId+'>'+data[i].addressName+'</option>');
				}
			},
			error:function(){
			}
		});
	}
});
//市级下拉框发生改变
$("#city1").change(function(){
	var cityId = $(this).val();
	var cityName = $(this).find("option[value="+cityId+"]").text();
	if(cityName=='市（选填）'){
		$("#county1").empty();
		$("#county1").prepend("<option value='county1'>县（选填）</option>");
	}else{
		$.ajax({
			type:"get",
			url:baseUrl+"customer/getAddressByParentId",
			data:{"parentId":cityId},
			async:false,
			success:function(data){
				$("#county1").empty();
				$("#county1").prepend("<option value='county1'>县（选填）</option>");
				for(var i=0;i<data.length;i++){
					$("#county1").append('<option value='+data[i].addressId+'>'+data[i].addressName+'</option>');
				}
			},
			error:function(){
			}
		});
	}
});
//增加新的收货地址
$("#renzhengSave").on("click",function(){
	var shopName = $("#renzhengShopName").val();
	var name = $("#renzhengName").val();
	var phone = $("#renzhengPhone").val();
	var detailAddress = $("#renzhengDetailAddress").val();
	var provinceId = $("#province1").val();
	var provinceName = $("#province1").find("option[value="+provinceId+"]").text();
	if(shopName!=""&&name!=""&&phone!=""&&detailAddress!=""&&provinceId!="province1"){
		var cityId = $("#city1").val();
		var cityName =$("#city1").find("option[value="+cityId+"]").text();
		var newCityName;
		if(cityId=="city1"){
			cityId = 0;
			cityName = null
			newCityName = "";
		}else{
			newCityName = cityName;
		}
		var countyId = $("#county1").val();
		var countyName =$("#county1").find("option[value="+countyId+"]").text();
		var newCountyName;
		if(countyId=="county1"){
			countyId = 0;
			countyName = null;
			newCountyName = "";
		}else{
			newCountyName = countyName;
		}
		var json = {
				"type" : "",
				"shopName" : shopName,
				"oneAddressId" : provinceId,
				"oneAddressName" : provinceName,
				"twoAddressId" : cityId,
				"twoAddressName" : cityName,
				"threeAddressId" : countyId,
				"threeAddressName" : countyName,
				"detailAddress" : detailAddress,
				"contactsPerson" : name,
				"contactsWay" : phone,
		};
		var jsonStr = JSON.stringify(json);
		post(baseUrl+"pay/payRechargeCertification",{"jsonStr":jsonStr});
	}else{
		tip.content("必填项不能为空!").show();
	}
});
});